<template>
  <div class="mainBook">
    <img src="@/assets/images/guidanceProposal.png" />
    <div class="rightContent">
      <div class="right-box">
        <div class="tags"> </div>
        <div class="title">内容填写</div>
      </div>
      <schema-form ref="dynamicForm" v-bind="formProps" @submit="confirm" class="bookForm">
      </schema-form>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, watch, withDefaults, defineProps } from 'vue';
  import { SchemaForm, type SchemaFormProps } from '@/components/core/schema-form';
  import { schemas } from './form-schema';
  import { docProduct } from '@/api/account';
  import { message } from 'ant-design-vue';

  defineOptions({
    name: '',
  });
  interface PropsDialog {
    id: string; //弹窗是否出现
  }
  const props = withDefaults(defineProps<PropsDialog>(), {
    id: '1',
  });
  const emit = defineEmits(['getDataUrl']);
  const dynamicForm = ref();
  const formProps: SchemaFormProps = { schemas, labelWidth: 38, showActionButtonGroup: false };
  // 点击提交
  function confirm(values) {
    dynamicForm.value?.validate().then(() => {
      let {
        shortName,
        charName,
        numberName,
        illegalAct,
        regulation,
        penalty,
        executeWay,
        info1,
        info2,
        info3,
      } = dynamicForm.value.getFieldsValue();
      if (info1) {
        info1 = '1.' + info1;
      }
      if (info2) {
        info2 = '2.' + info2;
      }
      if (info3) {
        info3 = '3.' + info3;
      }
      let params = {
        id: props.id,
        type: 11, //文书类型  6 当场处罚书 7 责令立改书 8责令限改书 9 检查意见书
        lastDate: '',
        writeMsg: '',
        shortName,
        charName,
        numberName,
        checkObjArr: [illegalAct, regulation, penalty, executeWay, info1, info2, info3],
      };
      params.checkObjArr = params.checkObjArr.filter(
        (item) => item !== '' && item !== undefined && item !== null,
      );

      docProduct(params).then((res) => {
        if (res.code == 0) {
          message.success('制作成功');
          emit('getDataUrl', res);
          dynamicForm.value.resetFields();
        }
      });
    });
  }
  defineExpose({
    confirm,
  });
</script>

<style lang="less" scoped>
  .mainBook {
    border-top: 1px solid #f0f0f0;
    display: flex;

    img {
      width: 508px;
      height: 873px;
    }
    .rightContent {
      padding: 24px;
      .right-box {
        display: flex;
        align-items: center;
        padding: 13px 0;
        .tags {
          border: 1px solid #0f53ac;
          margin-right: 7px;
          border-radius: 4px;
          height: 14px;
        }

        .title {
          font-size: 16px;
          font-weight: 400;
          line-height: 24px;
          color: rgba(68, 68, 68, 1);
        }
      }
    }
  }
</style>
